<?php

// TITLE: demographic
// FILE: demographic.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:52:13 PM
?>

		public function createDemographic($demographicId, $homeownerId) {
			global $con;
			$sql = 'INSERT INTO demographic (demographic_id, homeowner_id) VALUES (' . $demographicId . ', ' . $homeownerId . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readDemographic($id) {
			global $con;
			$sql = 'SELECT * FROM demographic WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$demographic = new Demographic();
				$demographic->setDemographicId($this->readDemographic($result[0]));
				$demographic->setHomeownerId($this->readHomeowner($result[1]));
			} else {
				$demographic = false;
			}
			return $demographic;
		}// end function

		public function updateDemographic($demographicId, $homeownerId) {
			global $con;
			$sql = 'UPDATE demographic SET demographic_id = ' . $demographic_id . ', homeowner_id = ' . $homeownerId . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteDemographic($id) {
			global $con;
			$sql = 'DELETE FROM demographic WHERE demographic_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listDemographic() {
			global $con;
			$sql = 'SELECT * FROM demographic';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$demographics = array();
				while ($result = mysqli_fetch_array($results)) {
					$demographic = new Demographic();
					$demographic->setDemographicId($this->readDemographic($result[0]));
					$demographic->setHomeownerId($this->readHomeowner($result[1]));
					$demographics[] = $demographic;
				}// end while
			} else {
				$demographics = false;
			}
			return $demographics;
		}// end function

		// demographic_type // --------------------

		public function createDemographicType($id, $title, $code, $description) {
			global $con;
			$sql = 'INSERT INTO demographic_type (id, title, code, description) VALUES (' . $id . ', ' . $title . ', ' . $code . ', ' . $description . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readDemographicType($id) {
			global $con;
			$sql = 'SELECT * FROM demographic_type WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$demographicType = new DemographicType();
				$demographicType->setId($result[0]);
				$demographicType->setTitle($result[1]);
				$demographicType->setCode($result[2]);
				$demographicType->setDescription($result[3]);
			} else {
				$demographicType = false;
			}
			return $demographicType;
		}// end function

		public function updateDemographicType($id, $title, $code, $description) {
			global $con;
			$sql = 'UPDATE demographic_type SET title = ' . $title . ', code = ' . $code . ', description = ' . $description . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteDemographicType($id) {
			global $con;
			$sql = 'DELETE FROM demographic_type WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listDemographicType() {
			global $con;
			$sql = 'SELECT * FROM demographic_type';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$demographicTypes = array();
				while ($result = mysqli_fetch_array($results)) {
					$demographicType = new DemographicType();
					$demographicType->setId($result[0]);
					$demographicType->setTitle($result[1]);
					$demographicType->setCode($result[2]);
					$demographicType->setDescription($result[3]);
					$demographicTypes[] = $demographicType;
				}// end while
			} else {
				$demographicTypes = false;
			}
			return $demographicTypes;
		}// end function
